package mvc_generator.generator.car.struts;

import mvc_generator.generator.car.struts.StrutsGenerator;
import mvc_generator.mVCGenerator.Config;
import mvc_generator.mVCGenerator.ModelMVC;
import mvc_generator.mVCGenerator.View;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.IFileSystemAccess;

@SuppressWarnings("all")
public class WebGenerator {
  public void generate(final ModelMVC model, final IFileSystemAccess fsa) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence webContent = _builder;
    StringConcatenation _builder_1 = new StringConcatenation();
    webContent = _builder_1;
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("\t\t");
    _builder_2.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    _builder_2.newLine();
    _builder_2.append("<web-app xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:web=\"http://java.sun.com/xml/ns/javaee\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\" id=\"WebApp_ID\" version=\"2.5\">");
    _builder_2.newLine();
    _builder_2.append("  ");
    _builder_2.append("<display-name>");
    String _name = model.getName();
    _builder_2.append(_name, "  ");
    _builder_2.append("</display-name>");
    _builder_2.newLineIfNotEmpty();
    _builder_2.append("  ");
    _builder_2.append("<welcome-file-list>");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("<welcome-file>pages/");
    Config _config = model.getConfig();
    View _indexView = _config.getIndexView();
    String _name_1 = _indexView.getName();
    _builder_2.append(_name_1, "    ");
    _builder_2.append("</welcome-file>");
    _builder_2.newLineIfNotEmpty();
    _builder_2.append("  ");
    _builder_2.append("</welcome-file-list>");
    _builder_2.newLine();
    _builder_2.append("  ");
    _builder_2.append("<servlet>");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("<servlet-name>action</servlet-name>");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("<init-param>");
    _builder_2.newLine();
    _builder_2.append("      ");
    _builder_2.append("<param-name>config</param-name>");
    _builder_2.newLine();
    _builder_2.append("<param-value>/WEB-INF/struts-config.xml</param-value>");
    _builder_2.newLine();
    _builder_2.append("</init-param>");
    _builder_2.newLine();
    _builder_2.append("<!-- The below example tells the container that the servlet will be loaded");
    _builder_2.newLine();
    _builder_2.append("at first.");
    _builder_2.newLine();
    _builder_2.append("The <load-on-startup> sub-element indicates the order in which each servlet");
    _builder_2.newLine();
    _builder_2.append("should be loaded.");
    _builder_2.newLine();
    _builder_2.append("Lower positive values are loaded first. If the value is negative or");
    _builder_2.newLine();
    _builder_2.append("unspecified,");
    _builder_2.newLine();
    _builder_2.append("then the container can load the servlet at anytime during startup -->");
    _builder_2.newLine();
    _builder_2.append("<load-on-startup>1</load-on-startup>");
    _builder_2.newLine();
    _builder_2.append("</servlet>");
    _builder_2.newLine();
    _builder_2.append("<!-- Action Servlet Mapping -->");
    _builder_2.newLine();
    _builder_2.append("<servlet-mapping>");
    _builder_2.newLine();
    _builder_2.append("<servlet-name>action</servlet-name>");
    _builder_2.newLine();
    _builder_2.append("<url-pattern>*.do</url-pattern>");
    _builder_2.newLine();
    _builder_2.append("</servlet-mapping>");
    _builder_2.newLine();
    _builder_2.append("<!-- declaring a JDBC data source -->");
    _builder_2.newLine();
    _builder_2.append("<resource-ref>");
    _builder_2.newLine();
    _builder_2.append("<description>JDBC resource to access my DB i.e.");
    _builder_2.newLine();
    _builder_2.append("dfj_hibernate</description>");
    _builder_2.newLine();
    _builder_2.append("<res-ref-name>jdbc/dsMyDB</res-ref-name>");
    _builder_2.newLine();
    _builder_2.append("<res-type>javax.sql.DataSource</res-type>");
    _builder_2.newLine();
    _builder_2.append("<res-auth>Container</res-auth>");
    _builder_2.newLine();
    _builder_2.append("</resource-ref>");
    _builder_2.newLine();
    _builder_2.append("</web-app>");
    _builder_2.newLine();
    webContent = _builder_2;
    String _name_2 = model.getName();
    String _plus = (_name_2 + "Struts");
    String _plus_1 = (_plus + StrutsGenerator.configPath);
    String _plus_2 = (_plus_1 + "web.xml");
    fsa.generateFile(_plus_2, webContent);
  }
}
